package cn.tedu.forum.passport.controller;


import cn.tedu.forum.commons.response.JsonResponse;
import cn.tedu.forum.passport.service.ILoginService;
import cn.tedu.forum.passport.pojo.dto.LoginDTO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;


/**
 * 用户登录控制类
 *
 * @author DunJu Zhou
 */
@RestController
@Slf4j
@Api(tags = "用户登录验证")
public class LoginController {
    @Autowired
    private ILoginService loginService;

    @PostMapping("/login")
    @ApiOperation("用户登录")
    //@ApiOperationSupport(order = 20)
    public JsonResponse<String> login(@Valid LoginDTO loginDTO) {
        loginService.login(loginDTO);
        log.debug("用户登录成功：{}", JsonResponse.ok());
        return JsonResponse.ok(loginService.login(loginDTO));
    }

    /*@RequestMapping("/currentUser")
    public UserInfo currentUser(HttpSession session) {
        //获取登录成功时保存的用户对象
        return (UserInfo) session.getAttribute("currUser");
    }

    @RequestMapping("/logout")
    public void logout(HttpSession session) {
        //删除登录成功时保存的用户对象
        session.removeAttribute("currUser");
    }*/
}
